﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Agro.Library;
using Ninject;
using Agro.Services;
using System.Data;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Agro.Models;

namespace Agro.Web.Areas.DataManage.Controllers
{
    public class ReportAnalyseController :    BaseController
    {
        //
        // GET: /DataManage/ReportAnalyse/
        [Inject]
        public IReportAnalyse ReportAnalyse { get; set; }
        public ActionResult Index(string reportid)
        {
             ViewBag.ReportID = reportid;
            T_Report report = ReportAnalyse.GetReport(reportid);
            ViewBag.CYCLE = report.Report_Cycle;
            ViewBag.GetOrganizeNodesUrl = Url.Content("~/SystemManage/Organization/GetChildOrganizationNodes/");
            return View();
        }

        public ActionResult GetReportTarget(string reportid)
        {
            DataTable dataTable = ReportAnalyse.GetReportTarget(reportid);
            string result = JsonConvert.SerializeObject(dataTable, new DataTableConverter());
            return Content(result);
        }
        public ActionResult GetReportLatitude(string reportid)
        {
            DataTable dataTable = ReportAnalyse.GetReportLatitude(reportid);
            string result = JsonConvert.SerializeObject(dataTable, new DataTableConverter());
            return Content(result);
        }
         [HttpPost]
        public ActionResult ReportCompute()
        {
            
            string year = Request["year"].ToString();
            string month1 = Request["month1"].ToString();
            string month2 = Request["month2"].ToString();
            string zb = Server.UrlDecode(Request["zb"].ToString());
            string wd = Server.UrlDecode(Request["wd"].ToString());
            string reportid = Request["reportid"].ToString();
            string dwid = Request["dwid"].ToString();
            string[] dwidarr = dwid.Split(',');
           // string content = ReportAnalyse.ReportCompute(reportid, zb, wd, CurrUser.UserInfo.User_OrganizationID.ToString());
            string content = ReportAnalyse.ReportCompute(reportid, year, month1, month2, zb, wd, dwidarr);
            return Content(content);
        }

        //public ActionResult GetTreeList(string reportid)
        //{


        //    DataTable dataTable = ReportAnalyse.GetReportTarget(reportid);

        //    DataRow dr=dataTable.NewRow();//添加指标
        //    dr["ID"] = "1";
        //    dr["NAME"] = "指标";
        //    dr["PARENTID"] = "0";
        //    dataTable.Rows.Add(dr);

        //    dr = dataTable.NewRow();//添加指标
        //    dr["ID"] = "2";
        //    dr["NAME"] = "维度";
        //    dr["PARENTID"] = "0";
        //    dataTable.Rows.Add(dr);


        //    DataTable dtLatitude = ReportAnalyse.GetReportLatitude(reportid);

        //    object[] obj = new object[dataTable.Columns.Count];
        //    for (int i = 0; i < dtLatitude.Rows.Count; i++)
        //    {
        //        dtLatitude.Rows[i].ItemArray.CopyTo(obj, 0);
        //        dataTable.Rows.Add(obj);
        //    }
        //    DataColumn dc = new DataColumn("open", typeof(Int32));
        //    dc.DefaultValue = 1;
        //    dataTable.Columns.Add(dc);
        //    string result = JsonConvert.SerializeObject(dataTable, new DataTableConverter());
        //    return Content(result);
  
        //}

    }
}
